﻿using System;
using Algoritmia.Utils;
using Algoritmia.DataStructures.Lists;

namespace Algoritmia.Problems.Searching
{
    public class NaiveSequentialSearcher<T> : ISortedSearcher<T>
    {
        #region ISortedSearcher<T> Members

        public int IndexOf(IList<T> list,T elem, Comparison<T> comparison = null)
        {
            comparison = AlgoritmiaFactory.GetDefaultComparison(comparison);
            int index = -1;
            for (int i = 0; i < list.Count; i++ )
            {
                if (comparison(elem, list[i]) == 0)
                    index = i;
            }
            return index;
        }

        #endregion
    }
}
